import { createRouter, createWebHashHistory } from "vue-router";
import { getUserType, getToken, log } from "../utils/user"

let routes = [
    {
        path: '/',
        redirect: '/login'
    },
    {
        path: "/",
        name: "Home",
        component: () => import( /* webpackChunkName: "home" */ "../views/home.vue"),
        children: [
            {
                path: "/main",
                name: "main",
                meta: {
                    title: '主界面',
                },
                component: () => import( /* webpackChunkName: "account" */ "../views/main.vue")
            },
            {
                path: "/account",
                name: "account",
                meta: {
                    title: '账号管理',
                },
                component: () => import( /* webpackChunkName: "account" */ "../views/account.vue")
            },
            {
                path: "/tag",
                name: "tag",
                meta: {
                    title: '标签管理',
                },
                component: () => import( /* webpackChunkName: "depart" */ "../views/tag.vue")
            },
            {
                path: "/staff",
                name: "staff",
                meta: {
                    title: '员工管理',
                },
                component: () => import( /* webpackChunkName: "staff" */ "../views/staff.vue")
            },
            {
                path: "/room",
                name: "room",
                meta: {
                    title: '病房管理',
                },
                component: () => import( /* webpackChunkName: "room" */ "../views/room.vue")
            },
            {
                path: "/bed",
                name: "bed",
                meta: {
                    title: '床位管理',
                },
                component: () => import( /* webpackChunkName: "bed" */ "../views/bed.vue")
            },
            {
                path: "/patient",
                name: "patient",
                meta: {
                    title: '患者管理',
                },
                component: () => import( /* webpackChunkName: "patient" */ "../views/patient.vue")
            },
            {
                path: "/barcode",
                name: "barcode",
                meta: {
                    title: '条码库',
                },
                component: () => import( /* webpackChunkName: "barcode" */ "../views/barcode.vue")
            },
            {
                path: "/scan",
                name: "scan",
                meta: {
                    title: '扫码记录',
                },
                component: () => import( /* webpackChunkName: "scan" */ "../views/scan.vue")
            },
            {
                path: "/vital",
                name: "vital",
                meta: {
                    title: '体征记录',
                },
                component: () => import( /* webpackChunkName: "vital" */ "../views/vital.vue")
            },
            {
                path: "/advice",
                name: "advice",
                meta: {
                    title: '医嘱管理',
                },
                component: () => import( /* webpackChunkName: "advice" */ "../views/advice.vue")
            },
            {
                path: "/alarm",
                name: "alarm",
                meta: {
                    title: '警报列表',
                },
                component: () => import( /* webpackChunkName: "alarm" */ "../views/alarm.vue")
            },
            {
                path: "/dell",
                name: "dell",
                meta: {
                    title: '报警页',
                },
                component: () => import( /* webpackChunkName: "dell" */ "../views/dell.vue")
            },
            {
                path: "/edu",
                name: "edu",
                meta: {
                    title: '健康宣教',
                },
                component: () => import( /* webpackChunkName: "edu" */ "../views/edu.vue")
            },
            {
                path: "/msg",
                name: "msg",
                meta: {
                    title: '消息列表',
                },
                component: () => import( /* webpackChunkName: "msg" */ "../views/msg.vue")
            },
            {
                path: "/msgLog",
                name: "msgLog",
                meta: {
                    title: '消息记录',
                },
                component: () => import( /* webpackChunkName: "msgLog" */ "../views/msgLog.vue")
            },
            {
                path: "/log",
                name: "log",
                meta: {
                    title: '操作日志',
                },
                component: () => import( /* webpackChunkName: "msgLog" */ "../views/log.vue")
            },
            {
                path: "/imitate",
                name: "imitate",
                meta: {
                    title: '模拟数据',
                },
                component: () => import( /* webpackChunkName: "imitate" */ "../views/imitate.vue")
            },
        ]
    }, {
        path: "/login",
        name: "Login",
        meta: {
            title: '登录'
        },
        component: () => import( /* webpackChunkName: "login" */ "../views/login.vue")
    },
    {
        path: "/403",
        name: "403",
        meta: {
            title: '403'
        },
        component: () => import( /* webpackChunkName: "403" */ "../views/403.vue")
    }
]

// 读取用户类型
const router = createRouter({
    history: createWebHashHistory(),
    routes
});



router.beforeEach((to, from, next) => {
    document.title = `${to.meta.title} | 智慧医院`;
    // if (!token && to.path !== '/login') {
    //     next('/login');
    // } else if (to.meta.permission) {
    //     // 判断路由权限
    //     log("router", userInfoType, to)
    //     userInfoType == to.meta.permission
    //         ? next()
    //         : next('/403');
    // } else {
    //     next();
    // }

    next();
});

export default router;